<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
$Document = array(
    'pageid' => 'login-index', //页面标示
    'pagename' => '登陆', //当前页面名称
    'mycss' => array('mobile/style'), //加载的css样式表
    'myjs' => array('global/jquery-1.9.0.min','global/layer/layer'), //加载的js脚本
    'footerjs'=>array(),
    'head'=>true//是否加载头部文件
);
include getTpl('header', 'public');
?>
<style type="text/css">
    .hide { display: none; }
</style>
<body>
<div class="content">
    <div class="logo">
        <img src="<?php echo IMG_PATH ?>mobile/logo.png"/>
    </div>
    <div class="login_wr r_warp">
        <form id="regForm">
        <div class="infor_box">
            <div class="phone_num">
                <input type="text" placeholder="请输入手机号" name="phone" id="phone">
                <b>
                    <svg t="1535443925203" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5615" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="25"><path d="M751.036141 162.03542 272.962835 162.03542l0 617.511056 478.073306 0L751.036141 162.03542zM561.799196 112.236224c0-5.477758-4.482081-9.959839-9.959839-9.959839l-99.598392 0c-5.477758 0-9.959839 4.482081-9.959839 9.959839l0 9.959839c0 5.477758 4.482081 9.959839 9.959839 9.959839l99.598392 0c5.477758 0 9.959839-4.482081 9.959839-9.959839L561.799196 112.236224zM512 899.064546c21.912056 0 39.839357-17.927301 39.839357-39.839357s-17.927301-39.839357-39.839357-39.839357c-21.912056 0-39.839357 17.927301-39.839357 39.839357S490.087944 899.064546 512 899.064546zM751.036141 958.823582 272.962835 958.823582c-32.867572 0-59.759035-26.891464-59.759035-59.759035L213.2038 122.196063c0-32.867572 26.891464-59.759035 59.759035-59.759035l478.073306 0c32.867572 0 59.759035 26.891464 59.759035 59.759035l0 776.868483C810.795177 931.932118 783.903713 958.823582 751.036141 958.823582z" p-id="5616"></path></svg>
                </b>
            </div>
            <div class="verify">
                <input type="text" placeholder="请输入验证码" name="captcha" id="captcha">
                <a href="javascript:;" class="getCode">获取验证码</a>
                <a href="javascript:;" class="seconds hide"></a>
            </div>
            <div class="password">
                <input type="password" placeholder="请输入密码（至少6位）" name="password_one" id="password_one">
                <b>
                    <svg t="1535421398352" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4198" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="25"><path d="M850.5 409.6l0-68.3C850.5 152.8 698.9 0 512 0 325.1 0 173.5 152.8 173.5 341.3l0 68.3L76.8 409.6l0 468.1c0 80.8 64.9 146.3 145.1 146.3l580.3 0c80.1 0 145.1-65.5 145.1-146.3L947.3 409.6 850.5 409.6zM256 349.9c0-150.8 116.2-273.1 259.5-273.1 153.6 0 252.5 131 252.5 292.6l0 40.2L256 409.6 256 349.9zM870.4 811.7c0 107.9-26.4 135.5-128 135.5L281.6 947.2c-102 0-128-27.2-128-135.5L153.6 486.4l716.8 0L870.4 811.7z" p-id="4199"></path><path d="M512 819.2c28.3 0 51.2-22.9 51.2-51.2L563.2 665.6c0-28.3-22.9-51.2-51.2-51.2-28.3 0-51.2 22.9-51.2 51.2L460.8 768C460.8 796.3 483.7 819.2 512 819.2z" p-id="4200"></path></svg>
                </b>
            </div>
            <div class="password">
                <input type="password" placeholder="请确认密码" class="a" name="password_two" id="password_two">
                <b>
                    <svg t="1535421398352" class="icon" style="" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4198" xmlns:xlink="http://www.w3.org/1999/xlink" width="20" height="25"><path d="M850.5 409.6l0-68.3C850.5 152.8 698.9 0 512 0 325.1 0 173.5 152.8 173.5 341.3l0 68.3L76.8 409.6l0 468.1c0 80.8 64.9 146.3 145.1 146.3l580.3 0c80.1 0 145.1-65.5 145.1-146.3L947.3 409.6 850.5 409.6zM256 349.9c0-150.8 116.2-273.1 259.5-273.1 153.6 0 252.5 131 252.5 292.6l0 40.2L256 409.6 256 349.9zM870.4 811.7c0 107.9-26.4 135.5-128 135.5L281.6 947.2c-102 0-128-27.2-128-135.5L153.6 486.4l716.8 0L870.4 811.7z" p-id="4199"></path><path d="M512 819.2c28.3 0 51.2-22.9 51.2-51.2L563.2 665.6c0-28.3-22.9-51.2-51.2-51.2-28.3 0-51.2 22.9-51.2 51.2L460.8 768C460.8 796.3 483.7 819.2 512 819.2z" p-id="4200"></path></svg>
                </b>
            </div>
        </div>
        </form>
        <button class="r_btn blue" id="regBtn">注册账号</button>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        //发送验证码
        $(".getCode").click(function(){
            var phone = $("#phone").val();
            if(!phone) {
                layer.msg('请输入您的手机号');
                return false;
            }

            var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; 
            if(!myreg.test(phone)) { 
                layer.msg('请输入正确的手机号码'); 
                return false; 
            } 

            //检测手机号是否已被注册
            var url = "<?php echo U('login/checkPhoneRegister') ?>";
            $.post(url, {phone:phone}, function(result){
                if(result.status) {
                     sendMessage(phone);
                } else{
                    layer.msg(result.info); 
                    return false;
                }
            },"JSON");
        });

        /*点击改变按钮状态，已经简略掉ajax发送短信验证的代码*/  
        function sendMessage(phone) {
            var sendurl = "<?php echo U('login/sendMessage') ?>";
            $.post(sendurl , {phone : phone} , function(result){
                if(result.status) {
                    // layer.msg('短信已成功发送，请注意查收');
                    setBtndisabled();
                }else{
                    layer.msg(result.info);
                    return false;
                }
            }, "JSON"); 
        }


        function setBtndisabled() {
            var btn = $(".seconds");
            var sendbtn = $(".getCode");  
            var count = 60;  
            var resend = setInterval(function(){  
                count--;  
                if (count > 0){ 
                    btn.removeClass('hide'); 
                    btn.html("重新获取("+count+")");  
                    sendbtn.addClass('hide');
                    // $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});  
                }else {  
                    clearInterval(resend); 
                    sendbtn.html("获取验证码");  
                    sendbtn.removeClass('hide');
                    btn.addClass('hide');
                }  
            }, 1000);
        }


        //注册提交
        $("#regBtn").click(function(){
            $(this).attr('disabled' , true);
            var regUrl = "<?php echo U('login/register') ?>";
            $.post(regUrl , $("#regForm").serialize() , function(result){
                if(result.status){
                    layer.msg(result.info);
                    setTimeout(function () {
                      window.location.href = result.data;
                    }, 2000);
                }else{
                    layer.msg(result.info);
                    $("#regBtn").attr('disabled' , false);
                    return false;
                }
            },'json');
        });

    });
</script>
</body>
</html>